import 'es6-promise/auto';
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);
import mutations from './mutations';
import actions from './actions';
import message from './modules/message'
import _ from 'lodash'
import global from '../common/global'

var storeObj = _.defaultsDeep({
    modules: {
        message
    },
    state: {
        policy: {
            host: '',
            OSSAccessKeyId: '',
            policy: '',
            saveName: '',
            signature: ''
        },
        num: 0,
        userStatus: {},
        userInfo: {},
        allTips: {}
    },

    getters: {
        // from global module
        policy(state: any) {
            return state.policy
        },
        num(state: any) {
            return state.num
        },

        // 获取用户信息流程待梳理
        userInfo(state: any) {
            if (!_.isEmpty(state.userInfo)) {
                return state.userInfo;
            }
            let userinfo = localStorage.getItem('userInfo');
            return userinfo && JSON.parse(userinfo) || '';
        },
        getAllTips(state: any) {
            return state.allTips
        }
    },
    mutations,
    actions
}, global)

const store = new Vuex.Store(storeObj)

export {
    store
}